#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>

using namespace std;

string func(string& str)
{
    string t;
    int p = 0;
    for (auto ch : str)
    {
        if (isdigit(ch))
        {
            if (p == 0) { p = ch - '0'; }
            else {
                p = p * 10 + (ch - '0');
            }
        }
        else
        {
            if (!t.empty()) {
                p %= t.size();
                string tmpStr = t.substr(p);
                tmpStr += t.substr(0, p);
                t.swap(tmpStr);
                p = 0;
            }
            if (ch == 'R') {
                reverse(t.begin(), t.end());
            }
            else { t += ch; }
        }
    }
    return t;
}

int main()
{
    int T = 0; cin >> T;
    while (T--)
    {
        string str;
        cin >> str;
        // cout << str << endl;
        cout << func(str) << endl;
    }
    return 0;
}